﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Business_Layer;
using DTO;

public partial class ControlLogin : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Display();
        }
    }

    void Display()
    {
        DataTable table = (DataTable)Session["ThanhVien"];

        MultiView1.ActiveViewIndex = (table == null) ? 0 : 1;

        if (table != null)
        {
            lblHoTen.Text = (String)table.Rows[0]["Name"];
            lblEmail.Text = "Số dư: "+table.Rows[0]["SS"] + " SS";
            lblEmail.Visible = false;
            Image1.ImageUrl = "images/ava.png";
        }
    }

    protected void btnSignIn_Click(object sender, EventArgs e)
    {
       string user = txtUserID.Text;

       string pas = txtPassword.Text;
       DataTable table = Customer_BUS.CheckSignIn(user, pas);
       if (table.Rows.Count > 0)
        {
            Session["ThanhVien"] = table;

            if (!Request.Url.AbsoluteUri.EndsWith("ViewCart.aspx"))
            {
                Response.Redirect("MyAccount.aspx");
            }
            else
            {
                Response.Redirect("ViewCart.aspx");
            }
        }
        else
        {
            lblError.Text = "Đăng nhập thất bại";
        }

        
    }

    protected void lnkSignOut_Click(object sender, EventArgs e)
    {
        Session.Remove("ThanhVien");
        ShoppingCart Cart = (ShoppingCart)Session["ShoppingCart"];
        Cart.Clear();
        Response.Redirect("Default.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string user = txtUserID.Text;

        string pas = txtPassword.Text;
        DataTable table = Customer_BUS.CheckSignIn(user, pas);
        if (table.Rows.Count > 0)
        {
            Session["ThanhVien"] = table;

            if (!Request.Url.AbsoluteUri.EndsWith("ViewCart.aspx"))
            {
                Response.Redirect("MyAccount.aspx");
            }
            else
            {
                Response.Redirect("ViewCart.aspx");
            }
        }
        else
        {
            lblError.Text = "Đăng nhập thất bại";
        }
    }
}
